// Code generated by ent, DO NOT EDIT.

package ent

import (
	"fmt"
	"server/components/models/ent/forecast"
	"server/components/models/ent/region"
	"server/components/models/ent/weather"
	"strings"
	"time"

	"entgo.io/ent"
	"entgo.io/ent/dialect/sql"
)

// Forecast is the model entity for the Forecast schema.
type Forecast struct {
	config `json:"-"`
	// ID of the ent.
	ID int64 `json:"id,omitempty"`
	// Temperature holds the value of the "temperature" field.
	Temperature float64 `json:"temperature,omitempty"`
	// WindSpeed holds the value of the "windSpeed" field.
	WindSpeed float64 `json:"windSpeed,omitempty"`
	// PrecipitationAmount holds the value of the "precipitationAmount" field.
	PrecipitationAmount float64 `json:"precipitationAmount,omitempty"`
	// WeatherCondition holds the value of the "weatherCondition" field.
	WeatherCondition forecast.WeatherCondition `json:"weatherCondition,omitempty"`
	// DateTime holds the value of the "dateTime" field.
	DateTime time.Time `json:"dateTime,omitempty"`
	// Edges holds the relations/edges for other nodes in the graph.
	// The values are being populated by the ForecastQuery when eager-loading is set.
	Edges            ForecastEdges `json:"edges"`
	forecast_region  *int64
	weather_forecast *int64
	selectValues     sql.SelectValues
}

// ForecastEdges holds the relations/edges for other nodes in the graph.
type ForecastEdges struct {
	// Region holds the value of the region edge.
	Region *Region `json:"region,omitempty"`
	// RegionWeather holds the value of the regionWeather edge.
	RegionWeather *Weather `json:"regionWeather,omitempty"`
	// loadedTypes holds the information for reporting if a
	// type was loaded (or requested) in eager-loading or not.
	loadedTypes [2]bool
}

// RegionOrErr returns the Region value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e ForecastEdges) RegionOrErr() (*Region, error) {
	if e.Region != nil {
		return e.Region, nil
	} else if e.loadedTypes[0] {
		return nil, &NotFoundError{label: region.Label}
	}
	return nil, &NotLoadedError{edge: "region"}
}

// RegionWeatherOrErr returns the RegionWeather value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func (e ForecastEdges) RegionWeatherOrErr() (*Weather, error) {
	if e.RegionWeather != nil {
		return e.RegionWeather, nil
	} else if e.loadedTypes[1] {
		return nil, &NotFoundError{label: weather.Label}
	}
	return nil, &NotLoadedError{edge: "regionWeather"}
}

// scanValues returns the types for scanning values from sql.Rows.
func (*Forecast) scanValues(columns []string) ([]any, error) {
	values := make([]any, len(columns))
	for i := range columns {
		switch columns[i] {
		case forecast.FieldTemperature, forecast.FieldWindSpeed, forecast.FieldPrecipitationAmount:
			values[i] = new(sql.NullFloat64)
		case forecast.FieldID:
			values[i] = new(sql.NullInt64)
		case forecast.FieldWeatherCondition:
			values[i] = new(sql.NullString)
		case forecast.FieldDateTime:
			values[i] = new(sql.NullTime)
		case forecast.ForeignKeys[0]: // forecast_region
			values[i] = new(sql.NullInt64)
		case forecast.ForeignKeys[1]: // weather_forecast
			values[i] = new(sql.NullInt64)
		default:
			values[i] = new(sql.UnknownType)
		}
	}
	return values, nil
}

// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the Forecast fields.
func (f *Forecast) assignValues(columns []string, values []any) error {
	if m, n := len(values), len(columns); m < n {
		return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
	}
	for i := range columns {
		switch columns[i] {
		case forecast.FieldID:
			value, ok := values[i].(*sql.NullInt64)
			if !ok {
				return fmt.Errorf("unexpected type %T for field id", value)
			}
			f.ID = int64(value.Int64)
		case forecast.FieldTemperature:
			if value, ok := values[i].(*sql.NullFloat64); !ok {
				return fmt.Errorf("unexpected type %T for field temperature", values[i])
			} else if value.Valid {
				f.Temperature = value.Float64
			}
		case forecast.FieldWindSpeed:
			if value, ok := values[i].(*sql.NullFloat64); !ok {
				return fmt.Errorf("unexpected type %T for field windSpeed", values[i])
			} else if value.Valid {
				f.WindSpeed = value.Float64
			}
		case forecast.FieldPrecipitationAmount:
			if value, ok := values[i].(*sql.NullFloat64); !ok {
				return fmt.Errorf("unexpected type %T for field precipitationAmount", values[i])
			} else if value.Valid {
				f.PrecipitationAmount = value.Float64
			}
		case forecast.FieldWeatherCondition:
			if value, ok := values[i].(*sql.NullString); !ok {
				return fmt.Errorf("unexpected type %T for field weatherCondition", values[i])
			} else if value.Valid {
				f.WeatherCondition = forecast.WeatherCondition(value.String)
			}
		case forecast.FieldDateTime:
			if value, ok := values[i].(*sql.NullTime); !ok {
				return fmt.Errorf("unexpected type %T for field dateTime", values[i])
			} else if value.Valid {
				f.DateTime = value.Time
			}
		case forecast.ForeignKeys[0]:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for edge-field forecast_region", value)
			} else if value.Valid {
				f.forecast_region = new(int64)
				*f.forecast_region = int64(value.Int64)
			}
		case forecast.ForeignKeys[1]:
			if value, ok := values[i].(*sql.NullInt64); !ok {
				return fmt.Errorf("unexpected type %T for edge-field weather_forecast", value)
			} else if value.Valid {
				f.weather_forecast = new(int64)
				*f.weather_forecast = int64(value.Int64)
			}
		default:
			f.selectValues.Set(columns[i], values[i])
		}
	}
	return nil
}

// Value returns the ent.Value that was dynamically selected and assigned to the Forecast.
// This includes values selected through modifiers, order, etc.
func (f *Forecast) Value(name string) (ent.Value, error) {
	return f.selectValues.Get(name)
}

// QueryRegion queries the "region" edge of the Forecast entity.
func (f *Forecast) QueryRegion() *RegionQuery {
	return NewForecastClient(f.config).QueryRegion(f)
}

// QueryRegionWeather queries the "regionWeather" edge of the Forecast entity.
func (f *Forecast) QueryRegionWeather() *WeatherQuery {
	return NewForecastClient(f.config).QueryRegionWeather(f)
}

// Update returns a builder for updating this Forecast.
// Note that you need to call Forecast.Unwrap() before calling this method if this Forecast
// was returned from a transaction, and the transaction was committed or rolled back.
func (f *Forecast) Update() *ForecastUpdateOne {
	return NewForecastClient(f.config).UpdateOne(f)
}

// Unwrap unwraps the Forecast entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func (f *Forecast) Unwrap() *Forecast {
	_tx, ok := f.config.driver.(*txDriver)
	if !ok {
		panic("ent: Forecast is not a transactional entity")
	}
	f.config.driver = _tx.drv
	return f
}

// String implements the fmt.Stringer.
func (f *Forecast) String() string {
	var builder strings.Builder
	builder.WriteString("Forecast(")
	builder.WriteString(fmt.Sprintf("id=%v, ", f.ID))
	builder.WriteString("temperature=")
	builder.WriteString(fmt.Sprintf("%v", f.Temperature))
	builder.WriteString(", ")
	builder.WriteString("windSpeed=")
	builder.WriteString(fmt.Sprintf("%v", f.WindSpeed))
	builder.WriteString(", ")
	builder.WriteString("precipitationAmount=")
	builder.WriteString(fmt.Sprintf("%v", f.PrecipitationAmount))
	builder.WriteString(", ")
	builder.WriteString("weatherCondition=")
	builder.WriteString(fmt.Sprintf("%v", f.WeatherCondition))
	builder.WriteString(", ")
	builder.WriteString("dateTime=")
	builder.WriteString(f.DateTime.Format(time.ANSIC))
	builder.WriteByte(')')
	return builder.String()
}

// Forecasts is a parsable slice of Forecast.
type Forecasts []*Forecast
